<?php
/**
 * 我的钱包
 */

namespace app\api\controller\user;

use app\api\controller\Common;
use app\api\model\user\Membermodel;
use app\api\model\user\Ordermodel;
class Purse extends Common
{
    protected $data;
    public function initialize()
    {
        parent::initialize();
        $this->checkUserLogin(); // 验证登录
        $this->data = $this->request->except(['sign','accessKey','token']);
    }

    /**
     * 我的钱包-账单记录
     */
    public function index(){
        $uid = $this->user['id'];
        $page = $this->data['page'] ? $this->data['page'] : 1;
        $pageSize = $this->data['limit'] ? $this->data['limit'] : 20;
        $paginate = ['list_rows'=>$pageSize,'page'=>$page];
        $user_purse = db('user_purse')
            ->field('id, uid, status, order_type, create_time')
            ->where(['uid'=>$uid])
            ->order('create_time DESC')->paginate($paginate)->toArray();
        
        return $this->showSuccess('我的钱包-账单记录', $user_purse);
    }

    /**
     * 我的钱包-账单记录
     */
    public function view(){
        $uid = $this->user['id'];
        $user = db('users')
            ->field('account')
            ->where(['id'=>$uid])
            ->find();
        
        return $this->showSuccess('我的钱包-账单记录', ['amount'=>$user['account']]);
    }

    
   
}